﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using AddFileHeaders;

namespace AddFileHeaders
{
    internal partial class frmInput : Form
    {

        private CurrentFilters currentFilters = null;
        public List<Filter> Filters
        {
            get { return this.currentFilters.Filters; }
        }

        public string HeaderText
        {
            get { return this.txtHeader.Text; }
        }

        private Point mouseLoc = Point.Empty;

        private PopupWindow popupFilters = null;
        private PopupWindow popupNewFilter = null;

        public frmInput()
        {

            InitializeComponent();

            this.DialogResult = DialogResult.Cancel;

            FilterControl fc = new FilterControl();
            fc.AddFilter += new EventHandler(fc_AddFilter);
            this.panelHidden.Controls.Add(fc);
            this.popupNewFilter = new PopupWindow(fc);
            
            this.currentFilters = new CurrentFilters();
            this.currentFilters.DeleteFilter += new EventHandler(currentFilters_DeleteFilter);
            this.panelHidden.Controls.Add(this.currentFilters);
            this.popupFilters = new PopupWindow(this.currentFilters);
            
            // Add default filter
            this.AddFilter(new FileTypeFilter("cs"));

        }

        private void currentFilters_DeleteFilter(object sender, EventArgs e)
        {
            this.UpdateFilterCount();
        }

        private void fc_AddFilter(object sender, EventArgs e)
        {
            this.AddFilter(sender as Filter);
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.OK;
            this.Close();
        }

        private void btnModify_Click(object sender, EventArgs e)
        {
            this.popupFilters.Show(new Point(this.mouseLoc.X + this.btnModify.Left, this.mouseLoc.Y + this.btnModify.Top));
        }
 
        private void btnAddFilter_Click(object sender, EventArgs e)
        {
            this.popupNewFilter.Show(new Point(this.mouseLoc.X + this.btnAddFilter.Left, this.mouseLoc.Y + this.btnAddFilter.Top));
        }
        
        private void Button_MouseMove(object sender, MouseEventArgs e)
        {
            this.mouseLoc = e.Location;
        }

        private void AddFilter(Filter filter)
        {
            this.currentFilters.AddFilter(filter);
            this.UpdateFilterCount();
        }

        private void UpdateFilterCount()
        {
            this.btnModify.Text = string.Format("Modify Current Filters ({0})", this.Filters.Count);
        }
                
    }
}
